package Game;

import java.awt.Font;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.UnicodeFont;
import org.newdawn.slick.font.effects.ColorEffect;
import org.newdawn.slick.geom.Rectangle;

public class MenuBar {
	private UnicodeFont bar;
	
	private StringBuilder lives = new StringBuilder();
	private StringBuilder kills = new StringBuilder();
	
	private Tower menu = null;
	private Rectangle clickable = null;
	
	
	
	@SuppressWarnings("unchecked")
	public MenuBar(int totalLives) throws SlickException
	{
		bar = new UnicodeFont(new Font("SansSerif", Font.BOLD, 16));
		bar.addAsciiGlyphs();   
		bar.addGlyphs(400, 600); 
		bar.getEffects().add(new ColorEffect(java.awt.Color.WHITE)); 
		bar.loadGlyphs();
		
		lives.append("Lives: ");
		kills.append("Kills: ");
		update(totalLives, 0, 0);
		menu = new Tower(5, 13);
		clickable = new Rectangle(menu.getX(), menu.getY(), 50, 50);
		
		
	}
	/**
	 * Update the message string
	 * @param str the string to be showed
	 */
	public void update (int totalLives, int leaks, int totalKills)
	{
		lives.delete(6, lives.length());
		kills.delete(6, kills.length());
		
		lives.append(totalLives-leaks);
		lives.append("/");
		lives.append(totalLives);
		
		kills.append(totalKills);
		
	}
	
	public Tower clickMenu(float x, float y)
	{
		if (clickable.contains(x, y))
			return menu;
		else
			return null;
	}
	
	/**
	 * Draws the messages at the top of the screen
	 */
	public void draw()
	{
		menu.draw();
		bar.drawString(500, 670, lives.toString());
		bar.drawString(500, 685, kills.toString());	
	}
}
